﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;


namespace Sequence
{
    public partial class FrmGetParam : Form
    {
        public string sName = "";
        public string sValue = "";

        public FrmGetParam()
        {
            InitializeComponent();
        }

        public FrmGetParam(OleDbConnection oConnection,string sProcessId,string sStepId )
        {
            InitializeComponent();

            String sSql = "select t_api_qd_process_step.name || '>' || t_api_qd_process_step_params.name as value,t_api_qd_process_step_params.name ";
            sSql += "from t_api_qd_process_step_params ";
            sSql += "join t_api_qd_process_step on t_api_qd_process_step_params.process_id = t_api_qd_process_step.process_id and t_api_qd_process_step_params.step_id = t_api_qd_process_step.id ";
            sSql += "where ";
            sSql += "t_api_qd_process_step_params.params_type='O' ";
            sSql += "and t_api_qd_process_step_params.process_id=" + sProcessId + " ";
            sSql += "and t_api_qd_process_step_params.step_id<" + sStepId + " ";

            try
            {
                OleDbCommand command = new OleDbCommand(sSql, oConnection);
                OleDbDataReader oDataReader = command.ExecuteReader();

                while (oDataReader.Read())
                {
                    ListViewItem oListViewItem = listView1.Items.Add(oDataReader["NAME"].ToString());
                    oListViewItem.SubItems[0].Text = oDataReader["NAME"].ToString();
                    oListViewItem.SubItems.Add(oDataReader["VALUE"].ToString());                               
                }
                ListViewItem oListViewItem2 = listView1.Items.Add("ToDo");
                oListViewItem2.SubItems[0].Text = "ToDo";
                oListViewItem2.SubItems.Add("?");

                oDataReader.Close();
                oDataReader.Dispose();
                command.Dispose();

            }
            catch (Exception ex)
            {
                //WriteError(ex.Message + " (" + sSql + ")");
            }
        }
        public FrmGetParam(OleDbConnection oConnection, string sSql)
        {
            InitializeComponent();

            try
            {
                OleDbCommand command = new OleDbCommand(sSql, oConnection);
                OleDbDataReader oDataReader = command.ExecuteReader();

                while (oDataReader.Read())
                {
                    ListViewItem oListViewItem = listView1.Items.Add(oDataReader["NAME"].ToString());
                    oListViewItem.SubItems[0].Text = oDataReader["NAME"].ToString();
                    oListViewItem.SubItems.Add(oDataReader["VALUE"].ToString());
                }
                

                oDataReader.Close();
                oDataReader.Dispose();
                command.Dispose();

            }
            catch (Exception ex)
            {
                //WriteError(ex.Message + " (" + sSql + ")");
            }
        }

        private void FrmGetParam_Load(object sender, EventArgs e)
        {

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                sName = listView1.SelectedItems[0].Text;
                sValue = listView1.SelectedItems[0].SubItems[1].Text;                   
            }

            this.Close();
        }
    }
}
